Skip to content

Use "$container" consistently #18299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2023
Merged

Conversation

nicolas-grekas
Copy link
Member

Takes the other road from #17683 as discussed in #18295

Using $containerBuilder and $containerConfigurator is unnecessarily long, consuming horizontal space without adding any clarity.

This also aligns the name $container with existing practice in the code and in recipes.

@nicolas-grekas
Copy link
Member Author

DOCtor-RST would need to be configured the other way around, asking ppl to rename to $container.
/cc @OskarStark I'm going to need your help on this one 🙏

@OskarStark
Copy link
Contributor

You can change it in .doctor-rst.yaml:

-- { type: 'ContainerConfigurator', name: 'containerConfigurator' }
+- { type: 'ContainerConfigurator', name: 'container' }

@nicolas-grekas
Copy link
Member Author

Thanks! PR updated.

@javiereguiluz
Copy link
Member

I'm still divided about this. I'm all in for as short as possible variable names. But, at the same time, variable names should be precise and self-explanatory.

"Container", "container builder" and "container configurator" are not the same (and they are implemented in three totally different classes). If we have ContainerBuilder type-hint, I still think that $containerBuilder is the best variable name; if we absolutely want a 1-word variable, it should be $builder and not $container (because this is not the service container, but an utility to build it).

Let's ask others @symfony/team-symfony-docs Thanks!

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented May 10, 2023

We're using $container in eg compiler passes and DI extensions, and $container in PHP config files and this doesn't create any confusion because everyone knows the context when opening those files.

nicolas-grekas added a commit to symfony/symfony that referenced this pull request May 10, 2023
…er builder+configurator (nicolas-grekas)

This PR was merged into the 6.3 branch.

Discussion
----------

Consistently use var $container to reference the container builder+configurator

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Related to symfony/symfony-docs#18299

The vast majority of the code base uses `$container` to reference either the `ContainerBuilder` or the `ContainerConfigurator`, depending on the context.

There are just a few inconsistencies, fixed in this PR.

Commits
-------

3f2c196 Consistently use var $container to reference the container builder+configurator
@wouterj
Copy link
Member

wouterj commented May 10, 2023

Like I also said in the original issue: to me, this is a non-issue and we should just choose one and use it. As long as it's not an abbreviation ($c), it won't matter much and consistency is more important to me than the word.

I think Nicolas makes a good point that we're now inconsistent with the code, which makes it (a) harder to read the code after learning the docs and (b) trigger errors from static analysers which have become very strict with names after the introduction of named parameters. So I think it's indeed good to move to the same naming standard as Symfony code.

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ok for me - type-hints are there as well, of course, to help.

@OskarStark
Copy link
Contributor

Thank you Nicolas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants